package com.sxbbc.plat.controller.banks;


import com.alibaba.fastjson.JSONObject;
import com.sxbbc.bank.service.IBankLoanService;
import com.sxbbc.common.basics.rest.RestResponse;
import com.sxbbc.common.core.dto.banks.BankLoanVo;
import com.sxbbc.common.core.entity.banks.BankLoan;
import com.sxbbc.common.core.utils.BasePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;




@Controller
public class BankLoanController {

    @Autowired
    private IBankLoanService iBankLoanService;

    @RequestMapping(value = "/bankloan/list")
    public ModelAndView list() {
        ModelAndView view = new ModelAndView("/banks/bankloan/list");
        return view;
    }


    @RequestMapping(value = "/bankloan/save")
    public ModelAndView savePage() {
        ModelAndView view = new ModelAndView("/banks/bankloan/save");
        return view;
    }



    @RequestMapping(value ="/bankloan/listDate")
    @ResponseBody
    public RestResponse listDate(BasePage<BankLoan> page, BankLoan bankLoan) {
        return iBankLoanService.listDate(page,bankLoan);
    }

    @RequestMapping(value ="/bankloan/saveDate",method = RequestMethod.POST)
    @ResponseBody
    public RestResponse saveDate(@RequestBody JSONObject jsonObject) {
        RestResponse restResponse=new RestResponse();
        BankLoanVo bankLoanVo= JSONObject.toJavaObject(jsonObject, BankLoanVo.class);
        iBankLoanService.saveBankLoan(bankLoanVo);
        restResponse.setCode("200");
        restResponse.setMsg("保存成功");
        return restResponse;
    }

    /**
     * 查看详情
     * @return
     */
    @RequestMapping(value = "/bankloan/details")
    public ModelAndView details(String id) {
        ModelAndView view = new ModelAndView("/banks/bankloan/details");
        BankLoanVo bankLoanVo=iBankLoanService.getBankLoanById(id);
        view.addObject("bankLoan",bankLoanVo.getBankLoan());
        view.addObject("bankLoanSub",bankLoanVo.getBankLoanFieldMaintainSubVos());
        return view;
    }

    /**
     * 编辑
     * @return
     */
    @RequestMapping(value = "/bankloan/edit")
    public ModelAndView edit(String id) {
        ModelAndView view = new ModelAndView("/banks/bankloan/edit");
        BankLoanVo bankLoanVo=iBankLoanService.getBankLoanById(id);
        view.addObject("bankLoan",bankLoanVo.getBankLoan());
        view.addObject("bankLoanSub",bankLoanVo.getBankLoanFieldMaintainSubVos());
        return view;
    }

    @RequestMapping(value ="/bankloan/updateDate",method = RequestMethod.POST)
    @ResponseBody
    public RestResponse updateDate(@RequestBody JSONObject jsonObject) {
        RestResponse restResponse=new RestResponse();
        BankLoanVo bankLoanVo= JSONObject.toJavaObject(jsonObject, BankLoanVo.class);
        iBankLoanService.update(bankLoanVo);
        restResponse.setCode("200");
        restResponse.setMsg("保存成功");
        return restResponse;
    }


}
